package com.learn.springcloud.hystrixexplainindetailconsumer;

import com.learn.springcloud.hystrixexplainindetailconsumer.command.naming.service.ThreadPoolPartitionAnnotationWay;
import com.learn.springcloud.hystrixexplainindetailconsumer.exception.handle.service.UserExceptionCatchAnnotationWay;
import com.learn.springcloud.hystrixexplainindetailconsumer.exception.handle.service.UserServiceException;
import com.learn.springcloud.hystrixexplainindetailconsumer.request.cache.service.RequestCacheAnnotation;
import com.learn.springcloud.hystrixexplainindetailconsumer.request.command.annotation.UserAnnotation;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
public class HystrixExplainInDetailConsumerApplication {

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    @Bean
    public UserAnnotation userAnnotation(){
        return new UserAnnotation(restTemplate());
    }

    @Bean
    public UserServiceException userServiceException(){
        return new UserServiceException(restTemplate());
    }

    @Bean
    public UserExceptionCatchAnnotationWay userExceptionCatch(){
        return new UserExceptionCatchAnnotationWay(restTemplate());
    }

    @Bean
    public ThreadPoolPartitionAnnotationWay threadPoolPartitionAnnotationWay(){
        return new ThreadPoolPartitionAnnotationWay(restTemplate());
    }

    @Bean
    public RequestCacheAnnotation requestCacheAnnotation(){
        return new RequestCacheAnnotation(restTemplate());
    }

    public static void main(String[] args) {
        SpringApplication.run(HystrixExplainInDetailConsumerApplication.class, args);
    }
}
